#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n = 0;
    cin >> n;
    vector<int> v(n, 0);
    for (int i = 0;i < n;i++)
    {
        cin >> v[i];
        //cerr<<v[i]<<" ";
    }
    //cerr<<endl;
    vector<int> dp(n, 0);
    dp[0] = v[0];
    for (int i = 1;i < n;i++)
    {
        if (dp[i - 1] > 0)
        {
            dp[i] = v[i] + dp[i - 1];
        }
        else
        {
            dp[i] = v[i];
        }
    }
    int max = -1000000000;
    for (auto& a : dp)
    {
        if (a > max) max = a;
        //cerr<<a<<" ";
    }
    //cerr<<endl;
   // cerr<<max<<endl;
    cout << max << endl;
    return 0;
}